#pragma once


#include "RBTree.h"

namespace cz
{
	template <class K,class V>
	struct MapOfKey
	{
		K operator()(const pair<K,V>& data)
		{
			return data.first;
		}
	};
	template <class K,class V>
	class Map
	{
	public:
		typedef typename RBTree<pair<K, V>, K, MapOfKey<K, V>>::iterator iterator;
		typedef typename RBTree<pair<K, V>, K, MapOfKey<K, V>>::const_iterator const_iterator;
		typedef typename RBTree<pair<K, V>, K, MapOfKey<K, V>>::reve_iterator reve_iterator;

		bool insert(const pair<K, V> val)
		{
			pair<RBtreeNode<pair<K,V>>*, bool> ret = _tree.Insert(val);
			return ret.second;
		}
		V& operator[](const K key)
		{
			pair<RBtreeNode<pair<K, V>>*, bool> ret = _tree.Insert(make_pair(key, V()));
			return ret.first->_data.second;
		}

		iterator find(const K key)
		{
			pair<RBtreeNode<pair<K,V>>*, bool> ret = _tree.Find(key);
			return iterator(ret.first);
		}
		void level_Traversal(void)
		{
			_tree.Level_Traversal();
		}

		iterator begin(void)
		{
			return _tree.begin();
		}
		iterator end(void)
		{
			return _tree.end();
		}

		reve_iterator rbegin()
		{
			return _tree.rbegin();
		}
		reve_iterator rend()
		{
			return _tree.rend();
		}
	private:
		RBTree<pair<K, V>,K, MapOfKey<K,V>> _tree;
	};

}
